<template>
        <div class="app-container">
        <el-form ref="form" :model="form" rules="rules" label-width="140px" size="medium">
            <el-form-item label="oneNET产品ID" prop="onenetProduceId">
                <el-input v-model="form.onenetProduceId" style="width:300px" />
            </el-form-item>
            <el-form-item label="oneNET设备ID" prop="onenetDeviceId" >
                <el-input v-model="form.onenetDeviceId" @blur="checkExist" style="width:300px" />
            </el-form-item>
            <el-form-item label="oneNET设备名称" prop="onenetDeviceName">
                <el-input v-model="form.onenetDeviceName" style="width:300px" />
            </el-form-item>          
            <el-form-item label="oneNET脚本名称" prop="onenetLuaName">
                <el-input v-model="form.onenetLuaName" style="width:300px" />
            </el-form-item>
            <el-form-item label="工段编号" prop="sectionNo">
                <el-input v-model="form.sectionNo" style="width:300px" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">添加</el-button>
                <el-button type="primary" @click="resetForm('form')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { saveOneNetInfo } from '../../api/oneNET.js'
export default {
    name: 'add_oneNET',
    data() {
        return {
            form: {
                onenetDeviceId: '',
                onenetDeviceName: '',
                onenetLuaName: '',
                sectionNo: '',
                onenetProduceId: ''
            }
        }
    },
    methods: {
        // 对表单进行重置
        resetForm(formItem) {
            this.$refs[formItem].resetFields()
        },
        // 对oneNET信息表单进行提交
        async onSubmit() {
          let query = Object.assign({},this.form)
          const data = await saveOneNetInfo(query)
          const errMsg = data.msg
          if(data.code == '1'){
            this.$message({
              showClose: true,
              message: errMsg,
              type: 'success'
            })
          }else{
            this.$message({
              showClose: true,
              message: errMsg,
              type: 'warning'
            })
          }
        },   
    }
}
</script>

<style>

</style>